package com.googlecode.perfectable.visuable.objectbrowser;

import java.util.HashMap;
import java.util.Map;

import com.googlecode.perfectable.eventable.routing.BaseSource;

public class MemoryInspectionService extends BaseSource<ObjectRegistration> implements InspectionService {
	private Map<Integer, Object> objects = new HashMap<>();

	@Override
	public void register(Object element) {
		@SuppressWarnings("boxing")
		Integer identifier = System.identityHashCode(element);
		boolean notify = this.objects.containsKey(identifier);
		this.objects.put(identifier, element);
		if(notify) {
			publish(new StandardObjectRegistration(identifier, element));
		}
	}

}
